home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 September / PCWorld_2008-09_cd.bin / v cisle / sadanastroju / IE7proSetup_2.3.exe / userscripts / GoogleLinkPreview.ieuser.js < prev    next >
Text File  |  2007-11-20  |  3KB  |  89 lines

  1. // ==UserScript==
  2. // @name          Google Link Preview
  3. // @namespace     http://loucypher.wordpress.com/
  4. // @include       http://www.google.*/search?*
  5. // @include       http://www.google.*/custom?*
  6. // @include       http://news.google.*/*
  7. // @description      Adds Clusty.com-like magnifiers on web and news search results to preview a link in a frame
  8. // ==/UserScript==
  9.  
  10. // Last updated: 2006-11-08
  11.  
  12. (function(){
  13. /*
  14. var XPath;
  15. if(location.hostname.match(/\.google\./)) {
  16.   if(location.hostname.match(/news/))
  17.     XPath = '//a[starts-with(@id, "r-") and count(img)=0]';
  18.   else if(location.href.match(/\/blogsearch\?/))
  19.     XPath = '//a[starts-with(@id, "p-") and count(img)=0]';
  20.   else
  21.     XPath = '//h2[@class="r"]/a[@class="l"]';
  22. } else if(location.hostname.match(/technorati\.com/))
  23.   XPath = '//div/ol/li/h3//a[@title]';
  24.  
  25.  
  26. var links = document.evaluate(XPath, document, null, 6, null);
  27. if(!links.snapshotLength) return;
  28. */
  29.  
  30.  function addEvent( obj, type, fn ) {
  31.      if ( obj.attachEvent ) {
  32.          obj["e"+type+fn] = fn;
  33.          obj[type+fn] = function() { obj["e"+type+fn]( window.event ); return false;}
  34.          obj.attachEvent( "on"+type, obj[type+fn] );
  35.      } else
  36.          obj.addEventListener( type, fn, false );
  37.  }
  38. function click_callback(e) {
  39.     //e.preventDefault();
  40.     var pOpen = "data:image/gif;base64,R0lGODlhDAAMAMIGAKZZWatkYcqfjsyikM2mk9KumfLsyPLsyCH5BAEKAAcALAAAAAAMAAwAAAMneEcRpFCFokqIi8Ly4MWfhB1hFnGgZgkj4wjAMEZDPEO1fB%2F5zg8JADs%3D";
  41.     var pClosed = "data:image/gif;base64,R0lGODlhDAAMAMIGAMwAAKtkYc2Tk8yikM2mk9KumQAAAAAAACH5BAEKAAcALAAAAAAMAAwAAAMyeEcRpFCFokqIix5xytvHtQHcJZDiKAQnR2gqCU1VizEsKWPtYEM%2F307BgfgGGMxgkAAAOw%3D%3D";
  42.  
  43.     //this.firstChild.src = this.firstChild.src == pOpen?pClosed:pOpen;
  44.     this.title = this.title == 'preview'?'close preview':'preview';
  45.     this.nextSibling.style.display = this.nextSibling.style.display == 'none'?'block':'none';
  46.     if(this.nextSibling.style.display == 'none') this.firstChild.src = pOpen;
  47.     else this.firstChild.src = pClosed;
  48.     //if(!this.nextSibling.hasAttribute('src'))
  49.     if(this.nextSibling.src == '')
  50.         this.nextSibling.src = this.previousSibling.href;
  51.  
  52.     return false;
  53.  
  54. }
  55.  
  56. var links = document.getElementsByTagName('a');
  57.  
  58. for(var i = 0; i < links.length; i++) {
  59.     var link = links[i];
  60.  
  61.     if(link.className != 'l') continue;
  62.  
  63.     //if(link.hasAttribute('onmousedown')) link.removeAttribute('onmousedown');
  64.  
  65.     var img = document.createElement('img');
  66.     img.alt = 'preview';
  67.     img.setAttribute('border', '0');
  68.     img.align = 'absmiddle';
  69.     img.src = 'data:image/gif;base64,R0lGODlhDAAMAMIGAKZZWatkYcqfjsyikM2mk9KumfLsyPLsyCH5BAEKAAcALAAAAAAMAAwAAAMneEcRpFCFokqIi8Ly4MWfhB1hFnGgZgkj4wjAMEZDPEO1fB%2F5zg8JADs%3D';
  70.     var pLink = document.createElement('a');
  71.     pLink.href = link.href;
  72.     pLink.title = 'preview';
  73.     pLink.style.marginLeft = '1em';
  74.  
  75.     addEvent(pLink, 'click', click_callback);
  76.  
  77.     pLink.appendChild(img);
  78.  
  79.     var iframe = document.createElement('iframe');
  80.     iframe.style.display = 'none';
  81.     iframe.width = '80%';
  82.     iframe.height = '350';
  83.     //iframe.appendChild(document.createTextNode(''));
  84.  
  85.     link.parentNode.insertBefore(iframe, link.nextSibling);
  86.     link.parentNode.insertBefore(pLink, link.nextSibling);
  87. }
  88. })();
  89.